﻿#pragma once
#include <unistd.h>
#include <string>
#include <tuple>
#include <map>
#include <functional>

using EventType = std::size_t;
using EventCallback = std::function<void(std::size_t)>;

struct EventCallData
{
    EventCallData() = default;
    EventCallData(EventType type, uint32_t times)
        : event_type(type), call_times(times) {}
    EventCallData operator + (const EventCallData &data)
    {
        return { event_type, this->call_times + data.call_times };
    }
    EventCallData& operator += (const EventCallData &data)
    {
        *this =  *this + data;
        return *this;
    }
    EventCallData& operator += (int32_t times)
    {
        this->call_times += times;
        return *this;
    }

    EventType event_type{ 0 };  ///< 事件类型
    uint32_t call_times{ 0 }; ///< 调用次数
};

/// 事件分发统计报告
struct EventCallReporter
{
    EventCallReporter() = default;
    ~EventCallReporter();
    using ObjPtrType = void *;
    using KeyType = std::pair<std::string, uint32_t>; ///< (filename, line_no)
    using EventCallInfo = std::map<KeyType, EventCallData>;

    ObjPtrType obj{ nullptr };  ///< 事件被派发者
    EventCallInfo event_call_info;
    // const char* filename{ nullptr };
};